package com.easyadmin.modules.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.SysBoundsEntity;
import com.easyadmin.modules.stock.domain.SysFactorEntity;
import com.easyadmin.modules.stock.domain.SysTradeDateEntity;
import com.easyadmin.modules.stock.mapper.SysBoundsDao;
import com.easyadmin.modules.stock.mapper.SysFactorDao;
import com.easyadmin.modules.stock.service.SysBoundsServer;
import com.easyadmin.modules.stock.service.SysFactorServer;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("sysBoundsServer")
public class SysBoundsServerImpl extends ServiceImpl<SysBoundsDao, SysBoundsEntity>
        implements SysBoundsServer {


    @Autowired
    SysBoundsDao sysEtfDao;

    @Override
    public PageInfo<SysBoundsEntity> queryPage(SysBoundsEntity sysFactorEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysBoundsEntity> data =sysEtfDao.selectList(new QueryWrapper<SysBoundsEntity>().lambda()
                .eq(StringUtils.isNotBlank(sysFactorEntity.getBondName()),
                        SysBoundsEntity::getBondName,sysFactorEntity.getBondName())
                .like(StringUtils.isNotBlank(sysFactorEntity.getStockName()),
                        SysBoundsEntity::getStockName,sysFactorEntity.getStockName())
                .orderBy(true,false, SysBoundsEntity::getListDate));
        return new PageInfo<>(data);
    }
    /**
     * Describe: 根据 id 删除某条数据
     * Param: id
     * Return: Boolean
     */
    @Override
    public Boolean remove(String id) {
        sysEtfDao.deleteById(Integer.valueOf(id));
        return true;
    }
    /**
     * Describe: 修改用户数据
     * Param: SysUser
     * Return: 操作结果
     */
    @Override
    public boolean update(SysBoundsEntity sysFactorEntity) {
        Integer result = sysEtfDao.updateById(sysFactorEntity);
        return result > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysEtfDao.deleteById(id);
        }
        return true;
    }

}
